<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'user-add', //页面标示
    'pagename' => '新建群组类型', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate','content/calendar'),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="fieldForm">
             <div class="form-group">
                <label class="col-sm-1 control-label">类型名称</label>
                <div class="col-sm-3">
                  <input type="text" name="title" id="title" placeholder="" class="form-control" value="<?php echo $field_info['title'];?>" />
                  <span class="help-block">名称长度为2-50个字符</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">简单介绍</label>
                <div class="col-sm-3">
				  <textarea name="note" id="note" placeholder="" class="form-control" value="" style="resize:none;"><?php echo $field_info['note'];?></textarea>
                  <span class="help-block">介绍长度为20-200个字符</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">群组添加表单类型</label>
                <div class="col-sm-3">
				  <select name="formtype" id="formtype" onchange="formtypeShow(this.value)" class="form-control" style="width:150px;">
				      <option value="text" <?php if($field_info['formtype']=="text"){echo "selected";}?>>用户自输入创建</option>
					  <option value="select" <?php if($field_info['formtype']=="select"){echo "selected";}?>>用户单选加入</option>
					  <option value="multi" <?php if($field_info['formtype']=="multi"){echo "selected";}?>>用户多选加入</option>
				  </select>
                  <span class="help-block"></span></div>
                <div class="col-sm-3"></div>
              </div>
              <div class="form-group" id="box_inputnum">
                <label class="col-sm-1 control-label">最多个数</label>
                <div class="col-sm-3">
                  <input type="text" name="inputnum" id="inputnum" placeholder="" class="form-control" style="width:150px;" value="<?php echo $field_info['inputnum'];?>" />
                  <span class="help-block">用户可加入群组最多个数</span></div>
              </div>
              <div class="form-group" id="box_choice">
                <label class="col-sm-1 control-label">可选值</label>
                <div class="col-sm-3">
                  <textarea name="choice" id="choice" placeholder="" class="form-control" value="" style="resize:none; width:200px; height:200px;"><?php echo $field_info['choice'];?></textarea>
                  <span class="help-block">每行一个值，例如输入:<br/>北京<br/>上海</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">人数下限</label>
                <div class="col-sm-3">
                  <input type="text" name="mtagminnum" id="mtagminnum" placeholder="" class="form-control" style="width:150px;" value="<?php echo $field_info['mtagminnum'];?>" />
                  <span class="help-block">当群组的成员数达到该数目时，才允许成员在群组内发话题和回帖。</span></div>
                <div class="col-sm-3"></div>
              </div>

              <div class="form-group">
                <label class="col-sm-1 control-label">群主指定</label>
                <div class="col-sm-3">
                  <input type="radio" name="manualmoderator" value="1" <?php if($field_info['manualmoderator']==1){echo "checked";}?>/>&nbsp;&nbsp;&nbsp;手工&nbsp;&nbsp;&nbsp;<input type="radio" name="manualmoderator" value="0" <?php if($field_info['manualmoderator']==0){echo "checked";}?>/>&nbsp;&nbsp;&nbsp;自动
                  <span class="help-block">如果选择不手工指定，则系统会自动将第一次使用某个群组的用户作为群主。</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">群主控制</label>
                <div class="col-sm-3">
                  <input type="radio" name="manualmember" value="1" <?php if($field_info['manualmember']==1){echo "checked";}?>/>&nbsp;&nbsp;&nbsp;群主可控制&nbsp;&nbsp;&nbsp;<input type="radio" name="manualmember" value="0" <?php if($field_info['manualmember']==0){echo "checked";}?>/>&nbsp;&nbsp;&nbsp;会员可自由加入
                  <span class="help-block">群主可控制，则允许群主有权设置群组的会员加入方式，来控制加入群组的会员。</span></div>
              </div>

              <div class="form-group">
                <label class="col-sm-1 control-label">显示顺序</label>
                <div class="col-sm-3">
                  <input type="text" name="displayorder" id="displayorder" placeholder="" class="form-control"style="width:150px;" value="<?php echo $field_info['displayorder'];?>" />
                  <span class="help-block"></span></div>
              </div>

              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                  	<input type="hidden" name="zid" id="zid" placeholder="" class="form-control" value="0" />
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<script>
function formtypeShow(formtype){
    if(formtype=="select"){
		$("#box_inputnum").hide();
		$("#box_choice").show();
	}else if(formtype=="multi"){
		$("#box_inputnum").show();
		$("#box_choice").show();
	}else{
		$("#box_inputnum").show();
		$("#box_choice").hide();
	}
}
$(function(){
	$("#box_choice").hide();
	
	var groupid=$.trim($("#groupid").val());
	$('#fieldForm').submit(function(){
		var title=$.trim($("#title").val());
		var note=$.trim($("#note").val());
		var formtype=$.trim($("#formtype").val());
		var choice=$("#choice").val();
		var isOk=true;
		if (!title){
			Msg.error('给类型取个名字吧');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if (!note){
			Msg.error('写点介绍吧！');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if(formtype=="select"){
			if (!choice){
				Msg.error('用户选择加入模式时可选项为必填');
				resetSubmit("#sub-ok",'保存');
				return false;
			}	
		}else if(formtype=="multi"){
			if (!choice){
				Msg.error('用户选择加入模式时可选项为必填');
				resetSubmit("#sub-ok",'保存');
				return false;
			}
			if (!inputnum){
				Msg.error('用户自建群组时最多个数为必填');
				resetSubmit("#sub-ok",'保存');
				return false;
			}		
		}else{
			if (!inputnum){
				Msg.error('用户自建群组时最多个数为必填');
				resetSubmit("#sub-ok",'保存');
				return false;
			}	
		}
		Msg.loading();
		  $.post('<?php echo U('wxgroup/field_add');?>',$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('添加成功',function(){
					document.location='<?php echo U('wxgroup/field');?>';	
				},3000);  
			}else{
				Msg.error(result.info);
			}
		  },'json');
		  
		  return false;
	})
	$("#groupid").change(function(){
		groupid=$(this).val();
		switch(groupid){
			case '1':case '2':case '6':
			$("#show-areazone").hide();
			$("#show-worker-info").hide();
			break;
			default:
			$("#show-areazone").show();
			$("#show-worker-info").show();
		}
	});
	$(".search-areazone").click(function(){
		var t=$(this).attr("rel");
		$("#ztitle").val('');
		$("#zid").val('');
		return false;
	})
	$("#select-areazone").click(function(){
		$(this).attr('href','<?php echo U('areazone/search',array(),true);?>');
	})
})
</script>
<?php
include getTpl('footer', 'public');
?>